cmake_minimum_required(VERSION 3.5)
project(ch15)

#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -w  -O0 -march=native -g -std=c++11")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w   -O0 -march=native -g -std=c++11")
# 定义可接收的参数
set(UBUNTU_VERSION "" CACHE STRING "Ubuntu version")
set(UBUNTU_CODENAME "" CACHE STRING "Ubuntu codename")

message(STATUS "Building for Ubuntu ${UBUNTU_VERSION} (${UBUNTU_CODENAME})")

set(CMAKE_CXX_STANDARD 14)  
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_BUILD_TYPE "Release")

find_package(Ceres REQUIRED)

find_package(Eigen3 REQUIRED)
include_directories(/usr/include/eigen3
		    /usr/include)

file(GLOB_RECURSE cartography 
	 "modules/node/*.h"
	 "modules/mapping/*.h"
)

include_directories(
    modules/
)

include_directories(${CERES_INCLUDE_DIRS})

add_library(${PROJECT_NAME} 
	modules/node/trajectory_options.cc
	modules/node/node_options.cc
	modules/node/node.cc
	modules/node/node_constants.cc

	modules/mapping/range_data_collator.cc
	modules/mapping/local_trajectory_builder_2d.cc
	modules/mapping/global_trajectory_builder.cc
    modules/mapping/map_builder_interface.cc
    modules/mapping/trajectory_builder_interface.cc
    modules/mapping/pose_extrapolator.cc
    modules/mapping/pose_extrapolator_interface.cc
    modules/mapping/imu_tracker.cc
	modules/mapping/eigen_quaterniond_from_two_vectors.cc
	modules/mapping/probability_values.cc
	modules/mapping/value_conversion_tables.cc
	modules/mapping/grid_2d.cc
	modules/mapping/trajectory_node.cc
	modules/mapping/probability_grid_range_data_inserter_2d.cc
	modules/mapping/ray_to_pixel_mask.cc
	modules/mapping/probability_grid.cc
	modules/mapping/tsdf_range_data_inserter_2d.cc
	modules/mapping/tsdf_2d.cc
	modules/mapping/normal_estimation_2d.cc
	modules/mapping/tsd_value_converter.cc
	modules/mapping/motion_filter.cc
	modules/mapping/submap_2d.cc
	modules/mapping/distance_map.cc
	
	modules/scan_matching/nearest_search.cc
	modules/scan_matching/real_time_correlative_scan_matcher_2d.cc
	modules/scan_matching/correlative_scan_matcher_2d.cc
	modules/scan_matching/occupied_grid_cost_function_2d.cc
	modules/scan_matching/occupied_space_cost_function_2d.cc
	modules/scan_matching/tsdf_match_cost_function_2d.cc
	modules/scan_matching/ceres_scan_matcher_2d.cc

    modules/sensor/point_cloud.cc
    modules/sensor/range_data.cc
    modules/sensor/imu_data.cc
    modules/sensor/odometry_data.cc
    modules/sensor/timed_point_cloud_data.cc
	modules/sensor/voxel_filter.cc

    modules/common/time.cc
	modules/common/ceres_solver_options.cc

	modules/publisher/publisher.cc

	${cartography}
)

find_package(OpenCV REQUIRED)

target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${CERES_LIBRARIES})

include_directories(
    apps/
)

find_package(Pangolin REQUIRED)
add_library(pangolin_viewer
            STATIC
            apps/pangolin_viewer/viewer.h
            apps/pangolin_viewer/color_scheme.h
            apps/pangolin_viewer/viewer.cc
            apps/pangolin_viewer/color_scheme.cc)

target_include_directories(pangolin_viewer 
                           PUBLIC
                           ${Pangolin_INCLUDE_DIR})
                           
target_link_libraries(pangolin_viewer
                      PUBLIC
                      ${PROJECT_NAME}
					  ${Pangolin_LIBRARIES}
)

add_executable(main_nclt apps/main_nclt.cc apps/read_data.cc)
target_link_libraries(main_nclt pangolin_viewer)

# 使用条件判断
#if(UBUNTU_VERSION VERSION_GREATER_EQUAL "22.04")
#	message(STATUS "Link for Ubuntu ${UBUNTU_VERSION}")
#    add_executable(main_nclt apps/main_nclt.cc apps/read_data.cc)
#	target_link_libraries(main_nclt ${PROJECT_NAME})
#endif()

#if(UBUNTU_VERSION VERSION_GREATER_EQUAL "16.04")
#	message(STATUS "Link for Ubuntu ${UBUNTU_VERSION}")
#	add_library(pangolin_viewer
#            STATIC
#            apps/pangolin_viewer/viewer.h
#            apps/pangolin_viewer/color_scheme.h
#            apps/pangolin_viewer/viewer.cc
#            apps/pangolin_viewer/color_scheme.cc)
#	target_link_libraries(pangolin_viewer
#                      PUBLIC
#                      ${PROJECT_NAME}
#                      #${OpenCV_LIBS}
#					  pangolin
#	)

#	add_executable(main apps/main.cc apps/read_data.cc)
#	target_link_libraries(main pangolin_viewer)
#endif()






